#include "dkglKernel.h"
#include "dkglDrawList.h"
#include "dkglScene.h"
#include "dkglViewport.h"
#include "dkglTestIntersection.h"

namespace DKGL
{
	Kernel::Kernel():
		_frmListener(NULL),
		_viewportManagerPtr(new ViewportManager(1)), // create only one viewport
		_sceneManagerPtr(new SceneManager())
	{
	}

	void Kernel::init()
	{
		MeshFactory& meshFactory = MeshFactory::instance();

		meshFactory.registerCreator(std::auto_ptr<MeshCreator>(new ObjModelCreator));
		meshFactory.registerCreator(std::auto_ptr<MeshCreator>(new BoxCreator));
	}


	void Kernel::update(float dt)
	{
		SceneManager::instance().refresh();
		physics::EvalOrientedBoundingBoxCollsion();
	}

	void Kernel::render(float dt)
	{
		glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		DrawList::Instance().flush();
	}

	void Kernel::onWindowResize(int width, int height)
	{
		ViewportManager::GetSingleton().resizeViewport(
			0,0, width, height); 
	}
}